import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class GameMenuSetUserNameFrame implements ActionListener {

	String user_name;

	JFrame game_menu_set_username_frame;
	JTextField game_menu_set_username_text_field;
	JButton game_menu_set_username_submit_button;

	GameMenuSetUserName game_menu_set_username_observable;

	public GameMenuSetUserNameFrame() {
		this.game_menu_set_username_frame = new JFrame();
		this.game_menu_set_username_frame.setLayout(null);
		this.game_menu_set_username_frame.setSize(new Dimension(400, 400));
		this.game_menu_set_username_frame
				.setLocation((int) Toolkit.getDefaultToolkit().getScreenSize()
						.getWidth() / 3, (int) Toolkit.getDefaultToolkit()
						.getScreenSize().getHeight() / 3);
		this.game_menu_set_username_frame.setVisible(false);
		this.game_menu_set_username_frame.setFocusable(false);

		this.game_menu_set_username_text_field = new JTextField();
		this.game_menu_set_username_text_field.setSize(100, 40);
		this.game_menu_set_username_text_field.setLocation(new Point(100, 100));
		this.game_menu_set_username_text_field.setVisible(true);

		this.game_menu_set_username_submit_button = new JButton("Submit");
		this.game_menu_set_username_submit_button
				.setSize(new Dimension(100, 40));
		this.game_menu_set_username_submit_button.setLocation(new Point(200,
				100));
		this.game_menu_set_username_submit_button.setVisible(true);
		this.game_menu_set_username_submit_button.addActionListener(this);

		this.game_menu_set_username_frame
				.add(this.game_menu_set_username_text_field);
		this.game_menu_set_username_frame
				.add(this.game_menu_set_username_submit_button);

		this.game_menu_set_username_observable = new GameMenuSetUserName();

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == this.game_menu_set_username_submit_button) {
			this.user_name = this.game_menu_set_username_text_field.getText();
			this.game_menu_set_username_observable.set_username_pressed();
			this.game_menu_set_username_frame.setVisible(false);
			this.game_menu_set_username_text_field.setText("");
		}

	}

}

class GameMenuSetUserName extends Observable {
	public void set_username_pressed() {
		this.setChanged();
		this.notifyObservers();
	}

}
